<?php
/**
 * Created by PhpStorm.
 * User: zhou
 * Date: 2019/3/17
 * Time: 下午2:12
 */

namespace App\Http\Controllers\Admin;


use App\Http\Controllers\ApiController;
use App\Http\Controllers\Controller;
use App\Models\MachineGoodsModel;
use App\Models\Template;
use Illuminate\Http\Request;

class TemplateController extends Controller
{
    public function index(Request $request,Template $template)
    {
        $list = Template::list() ? Template::list() -> toArray() : [
              'grid0'=>'','grid1'=>'','grid2'=>'','grid3'=>'','grid4'=>'','grid5'=>'','grid6'=>'',
              'template_name'=>'','template_id'=>0,
            ];
        $list = empty($list) ? [] :$list[0];
        return view('admin.template.index',['list'=>$list,'goods_list_api'=>url('admin/spu/template_spu_list'),'save_template_url'=>url('admin/template/save')]);
    }

    /**模板保存或者添加
     * @param Request $request
     * @param Template $template
     */
    public function save(Request $request,Template $template)
    {
        $res = Template::save_template($request->all());
        if($res){
            return ApiController::response(null,200,'成功');
        }else{
            return ApiController::response(null,400,'失败');
        }
    }


}